package com.dc.aimc.lab.controller;

import com.dc.aimc.common.service.response.JsonResponse;
import com.dc.aimc.lab.entity.ArticleFile;
import com.dc.aimc.user.api.UserFeignClient;
import com.dc.aimc.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("lab")
public class LabController {

    @Autowired
    private UserFeignClient userService;

    @GetMapping("getUser")
    public JsonResponse<User> getUser(String username) {
        return userService.getUserByUsername(username);
    }


    @PostMapping("upload")
    public JsonResponse<Object> upload(ArticleFile file) {
        MultipartFile[] multipartFiles = file.getFiles();
        for (MultipartFile multipartFile : multipartFiles) {
            String originalFilename = multipartFile.getOriginalFilename();
            System.out.println(originalFilename);
        }
        System.out.println(file.getName());
        return JsonResponse.success();
    }
}
